package com.sumainfor.pc.market.controller.rentadviser;

import com.sumainfor.common.util.ContextUtils;
import com.sumainfor.common.util.JsonResult;
import com.sumainfor.common.utlis.PageUtils;
import com.sumainfor.common.utlis.Pager;
import com.sumainfor.pc.market.service.RdHousingExcService;
import com.sumainfor.pc.market.service.RdHousingService;
import com.sumainfor.pc.market.service.RdTenantService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @Describe 房源换房
 */
@RestController
@RequestMapping("/rentadviser/RdHousingExcController")
public class RdHousingExcController implements Serializable {
    @Autowired
    private RdHousingExcService rdHousingExcService;
    /**
     *分页查询公共换房申请
     * @param
     * @return
     */
    @GetMapping("/getHouShelfIdListpublic")
    public JsonResult getHouShelfIdListpublic(@RequestParam Map<String,Object>params, Pager pager){
        JsonResult result=new JsonResult();
        params.put("ExcState","0");//换房申请状态（0 申请换房中 1已抢单 2租客取消）
        pager.setPagerNecessary(params, pager);
        PageUtils pageUtils = new PageUtils();
        Integer cout=rdHousingExcService.getHouShelfIdListCount(params);
        if(cout==0){
            return pageUtils.getJsonResult(new ArrayList<Map<String,Object>>(), params,cout);
        }
        List<Map<String,Object>>getCommunityList=rdHousingExcService.getHouShelfIdList(params);
        result=pageUtils.getJsonResult(getCommunityList, params, cout);
        return result;
    }
    /**
     *分页查询私有换房申请
     * @param
     * @return
     */
    @GetMapping("/getHouShelfIdList")
    public JsonResult getRepairList(@RequestParam Map<String,Object>params, Pager pager){
        JsonResult result=new JsonResult();
        params.put("ExcState","1");//换房申请状态（0 申请换房中 1已抢单 2租客取消）
        params.put("ShelfId", ContextUtils.getUserId());//租赁顾问的编号
        pager.setPagerNecessary(params, pager);
        PageUtils pageUtils = new PageUtils();
        Integer cout=rdHousingExcService.getHouShelfIdListCount(params);
        if(cout==0){
            return pageUtils.getJsonResult(new ArrayList<Map<String,Object>>(), params,cout);
        }
        List<Map<String,Object>>getCommunityList=rdHousingExcService.getHouShelfIdList(params);
        result=pageUtils.getJsonResult(getCommunityList, params, cout);
        return result;
    }

    /**
     * 换房申请抢单
     * @param params
     * @return
     */
    @PostMapping("/upHousingExc")
    public JsonResult upHousingExc(@RequestBody Map<String, Object> params) {
       params.put("ExcState",1);//0 申请换房中 1已抢单
       return rdHousingExcService.upHousingExc(params);
    }
    /**
     * 换房申请放弃
     * @param params
     * @return
     */
    @PostMapping("/upHousingExcGive")
    public JsonResult upHousingExcGive(@RequestBody Map<String, Object> params) {
        params.put("ExcState",0);//0 申请换房中 1已抢单
        return rdHousingExcService.upHousingExc(params);
    }

}
